<?php

namespace common\logics;

/**
 * RegionModel is the model behind the BaseDistrict.
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class RegionModel extends \common\models\base\BaseDistrict {

    /**
     * 用户默认收件地址
     * @return static
     */
    public static function loadData($pid = 0) {
        return static::find()->andWhere([
            'parent_id' => $pid
        ])->all();
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        $fields = [
            'id',
            'name',
            'code',
            'abbr',
            'letter',
            'pinyin',
        ];
        if (empty($this->children)) {
            $fields['leaf'] = function() {
                return true;
            };
        }
        return $fields;
    }

}
